#ifndef __AK7010_H
#define __AK7010_H

typedef struct MOTOR_FEEDBACK
{
        int id;                   //杩愭帶妯″紡涓嬬數鏈篒D
	float position_r;         //鐢垫満浣嶇疆鏁版嵁 鍗曚綅 rad
        float position_d;         //鐢垫満浣嶇疆鏁版嵁 鍗曚綅 deg
	float speed;              //鐢垫満閫熷害鏁版嵁 鍗曚綅 rad/s
	float current;            //鐢垫満鎵煩鏁版嵁 鍗曚綅 N.M
	int temperature;          //鐢垫満娓╁害 鍗曚綅 掳C
        int error;                //8浣嶆暟鎹?
        /********************
        0涓烘棤鏁呴殰锛?涓虹數鏈鸿繃娓╁害鏁呴殰锛?涓鸿繃鐢垫祦鏁呴殰锛?涓鸿繃鍘嬫晠闅滐紝
        4涓烘瑺鍘嬫晠闅滐紝5涓虹紪鐮佸櫒鏁呴殰锛?涓簃os绠¤繃娓╁害鏁呴殰锛?涓虹數鏈哄牭杞?
        *********************/
}MOTOR_FEEDBACK;

extern MOTOR_FEEDBACK AK7010_Data;

typedef enum {
  
      CAN_PACKET_SET_DUTY = 0,        /*占空比模式*/
      CAN_PACKET_SET_CURRENT,         /*电流环模式*/
      CAN_PACKET_SET_CURRENT_BRAKE,   /*电流刹车模式，给定电流使电机固定在当前位置并保持*/
      CAN_PACKET_SET_RPM,             /*转速模式，控制电机的转速*/
      CAN_PACKET_SET_POS,             /*电机以最大速度到达固定位置*/
      CAN_PACKET_SET_ORIGIN_HERE,     /*原点模式*/
      CAN_PACKET_SET_POS_SPD          /*以给定的速度和加速度运行到指定位置*/
        
} CAN_PACKET_ID;/*控制模式*/

/************************************************/
typedef struct temp_ak{
  
  float nowpos_d;               /*当前d轴*/
  float nowpos_r;               /*当前r轴*/
  float Pur_pos;//婢跺湱鎮嗛惃鍕窗閺嶅洣缍呯純? 2.2
  float stop_pos;//閹舵稓鎮嗛惃鍕粻濮濐澀缍呯純?
  float delta_d;
  float theta;//婢跺湱鎮嗛惄顔界垼娴ｅ秶鐤嗘稉搴＄秼閸撳秴銇欑憴?
  
  int change_mode;//鏉烆剚宕查崚浼?鐔峰閻ㄥ嫭鐖ｈ箛?
  int stop_flag;
  int back;//閸ョ偛鍩岄崢鐔剁秴閻ㄥ嫭鐖ｈ箛?
  uint8_t right_pos;    //when the claw rises the right position, right_pos = 1
  uint8_t ready_throw;  //after getting ball, puls 5°
}temp_ak;
extern temp_ak ak70_temp;

typedef struct temp_view{
  float deg;
  float v_change;
  float test_v;
  float test_p;
  float test_t;
  float test_kp;
  float test_kd;
}temp_view;
extern temp_view view;

/************************************************/

//浼烘湇妯″紡
void AK7010_data(uint8_t rx_data[8]);
void comm_can_transmit_eid(uint32_t id, const uint8_t *data, uint8_t len);
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index);
void buffer_append_int16(uint8_t* buffer, int16_t number, int16_t *index);
void AK7010_DutyMode(uint8_t controller_id, float duty);
void AK7010_CurrentMode(uint8_t controller_id, float current);
void AK7010_CurrentBreakMode(uint8_t controller_id, float current);
void AK7010_RPMMode(uint8_t controller_id, float rpm);
void AK7010_PosMode(uint8_t controller_id, float pos);
void AK7010_OriginMode(uint8_t controller_id, uint8_t set_origin_mode);
void AK7010_Pos_SpdMode(uint8_t controller_id, float pos,int16_t spd, int16_t RPA );

//杩愭帶妯″紡
void Can_senddata_to_AK70(uint8_t *buff, int len);
int float_to_uint(float x, float x_min, float x_max, unsigned int bits);
float uint_to_float(int x_int, float x_min, float x_max, int bits);
void Mit_pack_cmd(float p_des, float v_des, float kp, float kd, float t_ff);
void Mit_unpack_reply(uint8_t rx_data[]);


#endif